package xushuo.dao.entity.weixin.user;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;


/**
 * Create by zhangpe0312@qq.com on 2018/2/2.
 * <p>
 * 通过微信小程序获取用户的用户收货地址
 * <p>
 * 参数	类型	说明
 * errMsg	String	调用结果
 * userName	String	收货人姓名
 * postalCode	String	邮编
 * provinceName	String	国标收货地址第一级地址
 * cityName	String	国标收货地址第二级地址
 * countyName	String	国标收货地址第三级地址
 * detailInfo	String	详细收货地址信息
 * nationalCode	String	收货地址国家码
 * telNumber	String	收货人手机号码
 */
@Entity
@Table(name = "chooseAddressInfo")
public class ChooseAddressInfo implements GetInfo{

    private String id;

    private String errMsg;
    private String userName;
    private String postalCode;
    private String provinceName;
    private String cityName;
    private String countyName;
    private String detailInfo;
    private String nationalCode;
    private String telNumber;

    //最后修改时间
    private Date getTime;

    private UserLoginInfo userLoginInfo;

    private ChooseAddressInfo() {
    }

    @Id
    @Column(name = "id", nullable = false, unique = true)
    @GenericGenerator(name = "generator", strategy = "uuid")
    @GeneratedValue(generator = "generator")
    public String getId() {
        return id;
    }

    //关联表UserLoginInfo 为维护这个信息的对象
    @OneToOne(mappedBy = "addressInfo")
    public UserLoginInfo getUserLoginInfo() {
        return userLoginInfo;
    }

    @Column(name = "getTime",length = 19,updatable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getGetTime() {
        return getTime;
    }

    @Column(name = "errMsg", nullable = false, length = 32)
    public String getErrMsg() {
        return errMsg;
    }

    @Column(name = "userName", nullable = false, length = 32)
    public String getUserName() {
        return userName;
    }

    @Column(name = "postalCode", nullable = false, length = 32)
    public String getPostalCode() {
        return postalCode;
    }

    @Column(name = "provinceName", nullable = false, length = 32)
    public String getProvinceName() {
        return provinceName;
    }

    @Column(name = "cityName", nullable = false, length = 32)
    public String getCityName() {
        return cityName;
    }

    @Column(name = "countyName", nullable = false, length = 32)
    public String getCountyName() {
        return countyName;
    }

    @Column(name = "detailInfo", nullable = false, length = 32)
    public String getDetailInfo() {
        return detailInfo;
    }

    @Column(name = "nationalCode", nullable = false, length = 32)
    public String getNationalCode() {
        return nationalCode;
    }

    /**
     * 手机号是不重复的，固不可能重复
     * @return 用户的电话号码
     */
    @Column(name = "telNumber", nullable = false, length = 20,unique = true)
    public String getTelNumber() {
        return telNumber;
    }



    public static class Builder {

        ChooseAddressInfo addressInfo = new ChooseAddressInfo();

        public Builder setId(String id){
            addressInfo.setId(id);
            return this;
        }

        public Builder setUserLoginInfo(UserLoginInfo userLoginInfo){
            addressInfo.setUserLoginInfo(userLoginInfo);
            return this;
        }

        public Builder setErrMsg(String errMsg) {
            addressInfo.setErrMsg(errMsg);
            return this;
        }

        public Builder setUserName(String userName) {
            addressInfo.setUserName(userName);
            return this;
        }

        public Builder setPostalCode(String postalCode) {
            addressInfo.setPostalCode(postalCode);
            return this;
        }

        public Builder setProvinceName(String provinceName) {
            addressInfo.setProvinceName(provinceName);
            return this;
        }

        public Builder setCityName(String cityName) {
            addressInfo.setCityName(cityName);
            return this;
        }

        public Builder setCountyName(String countyName) {
            addressInfo.setCountyName(countyName);
            return this;
        }

        public Builder setDetailInfo(String detailInfo) {
            addressInfo.setDetailInfo(detailInfo);
            return this;
        }

        public Builder setNationalCode(String nationalCode) {
            addressInfo.setNationalCode(nationalCode);
            return this;
        }

        public Builder setTelNumber(String telNumber) {
            addressInfo.setTelNumber(telNumber);
            return this;
        }

        public Builder setGetTime() {
            addressInfo.setGetTime(new Date());
            return this;
        }

        public ChooseAddressInfo keep() {
            return addressInfo;
        }
    }


    public void setGetTime(Date getTime) {
        this.getTime = getTime;
    }

    public void setId(String id) {
        this.id = id;
    }


    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }


    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public void setCountyName(String countyName) {
        this.countyName = countyName;
    }

    public void setDetailInfo(String detailInfo) {
        this.detailInfo = detailInfo;
    }

    public void setNationalCode(String nationalCode) {
        this.nationalCode = nationalCode;
    }

    public void setTelNumber(String telNumber) {
        this.telNumber = telNumber;
    }

    public void setUserLoginInfo(UserLoginInfo userLoginInfo) {
        this.userLoginInfo = userLoginInfo;
    }

    @Override
    public String toString() {
        return "ChooseAddressInfo{" +
                "id='" + id + '\'' +
                ", errMsg='" + errMsg + '\'' +
                ", userName='" + userName + '\'' +
                ", postalCode='" + postalCode + '\'' +
                ", provinceName='" + provinceName + '\'' +
                ", cityName='" + cityName + '\'' +
                ", countyName='" + countyName + '\'' +
                ", detailInfo='" + detailInfo + '\'' +
                ", nationalCode='" + nationalCode + '\'' +
                ", telNumber='" + telNumber + '\'' +
                ", getTime=" + getTime +
                ", userLoginInfo=" + userLoginInfo +
                '}';
    }
}
